home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / C⁄C++ OS8 / Everything / Radios.cp < prev    next >
Encoding:
Text File  |  1998-09-06  |  8.8 KB  |  407 lines  |  [TEXT/CWIE]

  1. // Radios.cp
  2.  
  3. #include <Types.h>
  4. #include <Quickdraw.h>
  5. #include <Controls.h>
  6. #include <Dialogs.h>
  7. #include <Events.h>
  8. #include <Lists.h>
  9. #include <Menus.h>
  10. #include <Resources.h>
  11. #include <Sound.h>
  12. #include <TextEdit.h>
  13. #include <ToolUtils.h>
  14. #include <Appearance.h>
  15.  
  16. #include "Globals.h"
  17. #include "ResourceDefs.h"
  18. #include "DoScrap.h"
  19. #include "Miscellany.h"
  20. #include "Scrolling.h"
  21. #include "ControlUtils.h"
  22. #include "DDocData.h"
  23. #include "EverythingEngine.h"
  24. #include "EverythingDoc.h"
  25.  
  26. #include "Radios.h"
  27.  
  28.  
  29. //----------
  30. void    Radios::Create (
  31.     AMDoc*            inDoc,
  32.     DDocData*        inData)
  33. {
  34.     Radios*        winObj = new Radios;
  35.  
  36.     if (winObj != nil) {
  37.         winObj->Open (inDoc);
  38.         winObj->ConnectToData (inData);
  39.     }
  40. }
  41.  
  42. //----------
  43. Radios::Radios ()
  44. {
  45.     mData = nil;
  46. }
  47.  
  48. //----------
  49. Radios::~Radios ()
  50. {
  51. }
  52.  
  53. //----------
  54. EverythingEngine*    Radios::GetEngine ()
  55. {
  56.     return (EverythingEngine*) mDoc->mEngine;
  57. }
  58.  
  59. //----------
  60. void    Radios::Open (
  61.     AMDoc*            inDoc)
  62. {
  63.     WindowPtr        window;
  64.     Handle            wftb;
  65.  
  66.     mDoc = inDoc;
  67.  
  68.     window = GetNewCWindow (WIND_Radios, nil, (WindowPtr) -1L);
  69.     if (mDoc->mEngine->GetFilename () [0] != 0) {
  70.         SetWTitle (window, mDoc->mEngine->GetFilename ());
  71.     }
  72.     mWindow = window;
  73.     ((EverythingDoc*)mDoc)->mRadiosPtr = window;
  74.  
  75.     SetWindowKind (window, 'AM');
  76.     SetWRefCon (window, (long) this);
  77.     SetPort (window);
  78.     SetInfo (window);
  79.  
  80.     wftb = ::GetResource ('Wftb', WIND_Radios);
  81.  
  82.     CreateRootControl (window, &mRootControl);
  83.  
  84.     vScroll = nil;
  85.     hScroll = nil;
  86.  
  87.  
  88.     mRadioGroupGroupHandle = GetNewControl (CNTL_RadioGroupGroup, window);
  89.  
  90.     mStandard3Handle = ::GetNewControl (CNTL_Standard3, window);
  91.     EmbedControl (mStandard3Handle, mRadioGroupGroupHandle);
  92.     SetWindowItemFont (mStandard3Handle, wftb, 2);
  93.  
  94.     mGroupBoxHandle = GetNewControl (CNTL_GroupBox, window);
  95.     SetWindowItemFont (mGroupBoxHandle, wftb, 3);
  96.     mGroupGroupHandle = GetNewControl (CNTL_GroupGroup, window);
  97.     EmbedControl (mGroupGroupHandle, mGroupBoxHandle);
  98.     mGroupRadio1Handle = GetNewControl (CNTL_GroupRadio1, window);
  99.     SetWindowItemFont (mGroupRadio1Handle, wftb, 5);
  100.     EmbedControl (mGroupRadio1Handle, mGroupGroupHandle);
  101.     mGroupRadio2Handle = GetNewControl (CNTL_GroupRadio2, window);
  102.     SetWindowItemFont (mGroupRadio2Handle, wftb, 6);
  103.     EmbedControl (mGroupRadio2Handle, mGroupGroupHandle);
  104.     mGroupRadio3Handle = GetNewControl (CNTL_GroupRadio3, window);
  105.     SetWindowItemFont (mGroupRadio3Handle, wftb, 7);
  106.     EmbedControl (mGroupRadio3Handle, mGroupGroupHandle);
  107.  
  108.     mGraphic3BoxHandle = GetNewControl (CNTL_Graphic3Box, window);
  109.     SetWindowItemFont (mGraphic3BoxHandle, wftb, 8);
  110.     mGraphic3GroupHandle = GetNewControl (CNTL_Graphic3Group, window);
  111.     EmbedControl (mGraphic3GroupHandle, mGraphic3BoxHandle);
  112.  
  113.     mStopHandle = ::GetNewControl (CNTL_Stop, window);
  114.     EmbedControl (mStopHandle, mGraphic3GroupHandle);
  115.     SetWindowItemFont (mStopHandle, wftb, 10);
  116.  
  117.     mGoHandle = ::GetNewControl (CNTL_Go, window);
  118.     EmbedControl (mGoHandle, mGraphic3GroupHandle);
  119.     SetWindowItemFont (mGoHandle, wftb, 11);
  120.  
  121.     mBevel3BoxHandle = GetNewControl (CNTL_Bevel3Box, window);
  122.     SetWindowItemFont (mBevel3BoxHandle, wftb, 12);
  123.     mBevel3GroupHandle = GetNewControl (CNTL_Bevel3Group, window);
  124.     EmbedControl (mBevel3GroupHandle, mBevel3BoxHandle);
  125.  
  126.     mRadioButtonHandle = ::GetNewControl (CNTL_RadioButton, window);
  127.     EmbedControl (mRadioButtonHandle, mBevel3GroupHandle);
  128.     SetWindowItemFont (mRadioButtonHandle, wftb, 14);
  129.     SetBevelButtonGraphicAlignment (mRadioButtonHandle, kControlBevelButtonAlignCenter, 0, 0);
  130.  
  131.     mRadioButton2Handle = ::GetNewControl (CNTL_RadioButton2, window);
  132.     EmbedControl (mRadioButton2Handle, mBevel3GroupHandle);
  133.     SetWindowItemFont (mRadioButton2Handle, wftb, 15);
  134.     SetBevelButtonGraphicAlignment (mRadioButton2Handle, kControlBevelButtonAlignCenter, 0, 0);
  135.  
  136.     mTextBoxHandle = GetNewControl (CNTL_TextBox, window);
  137.     SetWindowItemFont (mTextBoxHandle, wftb, 16);
  138.     mTextGroupHandle = GetNewControl (CNTL_TextGroup, window);
  139.     EmbedControl (mTextGroupHandle, mTextBoxHandle);
  140.  
  141.     mNameHandle = ::GetNewControl (CNTL_Name, window);
  142.     EmbedControl (mNameHandle, mTextGroupHandle);
  143.     SetWindowItemFont (mNameHandle, wftb, 18);
  144.  
  145.     mKindHandle = ::GetNewControl (CNTL_Kind, window);
  146.     EmbedControl (mKindHandle, mTextGroupHandle);
  147.     SetWindowItemFont (mKindHandle, wftb, 19);
  148.  
  149.     mSizeHandle = ::GetNewControl (CNTL_Size, window);
  150.     EmbedControl (mSizeHandle, mTextGroupHandle);
  151.     SetWindowItemFont (mSizeHandle, wftb, 20);
  152.  
  153.     AdvanceKeyboardFocus (window);
  154.  
  155.     ShowWindow (window);
  156. }
  157.  
  158. //----------
  159. void    Radios::Close ()
  160. {
  161.     mData->RemoveResponder (this);
  162.  
  163.     ((EverythingDoc*)mDoc)->mRadiosPtr = nil;
  164.     SetInfo (nil);
  165.     HideWindow (mWindow);
  166.     DisposeWindow (mWindow);
  167.  
  168.     delete this;
  169. }
  170.  
  171. //----------
  172. void    Radios::ConnectToData (
  173.     DDocData*        inData)
  174. {
  175.     mData = inData;
  176.     mData->AddResponder (this);
  177.  
  178.     SetControlValue (mRadioGroupGroupHandle, mData->GetRadioGroup ());
  179.     SetControlValue (mGroupGroupHandle, mData->GetGroup ());
  180.     SetControlValue (mGraphic3GroupHandle, mData->GetGraphic ());
  181.     SetControlValue (mBevel3GroupHandle, mData->GetBevel ());
  182.     SetControlValue (mTextGroupHandle, mData->GetText ());
  183. }
  184.  
  185. //----------
  186. void    Radios::DataChanged (
  187.     long        inDataID)
  188. {
  189.     if (inDataID == idRadioGroup) {
  190.         SetControlValue (mRadioGroupGroupHandle, mData->GetRadioGroup ());
  191.     }
  192.     if (inDataID == idGroup) {
  193.         SetControlValue (mGroupGroupHandle, mData->GetGroup ());
  194.     }
  195.     if (inDataID == idGraphic) {
  196.         SetControlValue (mGraphic3GroupHandle, mData->GetGraphic ());
  197.     }
  198.     if (inDataID == idBevel) {
  199.         SetControlValue (mBevel3GroupHandle, mData->GetBevel ());
  200.     }
  201.     if (inDataID == idText) {
  202.         SetControlValue (mTextGroupHandle, mData->GetText ());
  203.     }
  204. }
  205.  
  206. //----------
  207. void    Radios::Control (
  208.     ControlHandle        whichControl,
  209.     short                whichPart,
  210.     Point                where)
  211. {
  212.     Rect            bounds;
  213.     short            newValue;
  214.  
  215.     ExitCurField ();
  216.  
  217.     if (whichControl == mRadioGroupGroupHandle) {
  218.         if (TrackClick (whichControl, where) != 0) {
  219.             mData->SetRadioGroup (GetControlValue (mRadioGroupGroupHandle));
  220.         }
  221.     }
  222.     if (whichControl == mGroupGroupHandle) {
  223.         if (TrackClick (whichControl, where) != 0) {
  224.             mData->SetGroup (GetControlValue (mGroupGroupHandle));
  225.         }
  226.     }
  227.     if (whichControl == mGraphic3GroupHandle) {
  228.         if (TrackClick (whichControl, where) != 0) {
  229.             mData->SetGraphic (GetControlValue (mGraphic3GroupHandle));
  230.         }
  231.     }
  232.     if (whichControl == mBevel3GroupHandle) {
  233.         if (TrackClick (whichControl, where) != 0) {
  234.             mData->SetBevel (GetControlValue (mBevel3GroupHandle));
  235.         }
  236.     }
  237.     if (whichControl == mTextGroupHandle) {
  238.         if (TrackClick (whichControl, where) != 0) {
  239.             mData->SetText (GetControlValue (mTextGroupHandle));
  240.         }
  241.     }
  242. }
  243.  
  244. //----------
  245. void    Radios::MouseIn (
  246.     Point        where,
  247.     short        modifiers)
  248. {
  249.     Rect        bounds;
  250.  
  251. }
  252.  
  253. //----------
  254. void    Radios::ExitCurField ()
  255. {
  256.     ControlHandle    focus;
  257.  
  258.     GetKeyboardFocus (mWindow, &focus);
  259.  
  260.     if (focus == nil) {
  261.         // nothing to exit
  262.  
  263.     }
  264. }
  265.  
  266. //----------
  267. void    Radios::TypeIn (
  268.     char        ch)
  269. {
  270.     ControlHandle    focus;
  271.     SInt16            keyCode;
  272.  
  273.     GetKeyboardFocus (mWindow, &focus);
  274.  
  275.     if ((ch == charEnter)
  276.     ||  (ch == charReturn)) {
  277.         ExitCurField ();
  278.     } else if (ch == charEsc) {
  279.     } else if (ch == charTab) {
  280.         DoTab ((curEvent.modifiers & optionKey) != 0);
  281.     } else if (focus != nil) {
  282.         keyCode = (SInt16)(curEvent.message & keyCodeMask);
  283.         HandleControlKey (focus, keyCode, ch, (SInt16)curEvent.modifiers);
  284.         mDoc->mEngine->SetDirty ();
  285.     } else {
  286.         SysBeep (1);
  287.     }
  288. }
  289.  
  290. //----------
  291. void    Radios::Resize ()
  292. {
  293.     /* application-specific code to resize items in window */
  294. }
  295.  
  296. //----------
  297. void    Radios::Scroll (
  298.     short        newValue,
  299.     short        oldValue)
  300. {
  301.     /* application-specific code to scroll window */
  302.     if (gWhichScroll == vScroll) {
  303.     } else {    // horizontal
  304.     }
  305. }
  306.  
  307. //----------
  308. void    Radios::DoUndo ()
  309. {
  310. } // DoUndo
  311.  
  312. //----------
  313. void    Radios::DoCut ()
  314. {
  315.     TEHandle        curTE = GetCurTE ();
  316.  
  317.     if (curTE != nil) {
  318.         TECut (curTE);
  319.         mDoc->mEngine->SetDirty ();
  320.         scrapDirty = true;
  321.     }
  322. } // DoCut
  323.  
  324. //----------
  325. void    Radios::DoCopy ()
  326. {
  327.     TEHandle        curTE = GetCurTE ();
  328.  
  329.     if (curTE != nil) {
  330.         TECopy (curTE);
  331.         scrapDirty = true;
  332.     }
  333. } // DoCopy
  334.  
  335. //----------
  336. void    Radios::DoPaste ()
  337. {
  338.     TEHandle        curTE = GetCurTE ();
  339.  
  340.     if (curTE != nil) {
  341.         TEPaste (curTE);
  342.         mDoc->mEngine->SetDirty ();
  343.     }
  344. } // DoPaste
  345.  
  346. //----------
  347. void    Radios::DoClear ()
  348. {
  349.     TEHandle        curTE = GetCurTE ();
  350.  
  351.     if (curTE != nil) {
  352.         TEDelete (curTE);
  353.         mDoc->mEngine->SetDirty ();
  354.     }
  355. } // DoClear
  356.  
  357. //----------
  358. void    Radios::DoSelectAll ()
  359. {
  360.     TEHandle        curTE = GetCurTE ();
  361.  
  362.     if (curTE != nil) {
  363.         TESetSelect (0, 32767, curTE);
  364.     }
  365. } // DoSelectAll
  366.  
  367. //----------
  368. void    Radios::DoShowClipboard ()
  369. {
  370. } // DoShowClipboard
  371.  
  372. //----------
  373. Boolean        Radios::DoCommand (
  374.     long        inCommand)
  375. {
  376.     Boolean        result = true;
  377.  
  378.     switch (inCommand) {
  379.         case cmdUndo:
  380.                 DoUndo ();
  381.             break;
  382.         case cmdCut:
  383.                 DoCut ();
  384.             break;
  385.         case cmdCopy:
  386.                 DoCopy ();
  387.             break;
  388.         case cmdPaste:
  389.                 DoPaste ();
  390.             break;
  391.         case cmdClear:
  392.                 DoClear ();
  393.             break;
  394.         case cmdSelectAll:
  395.                 DoSelectAll ();
  396.             break;
  397.         case cmdShowClipboard:
  398.                 DoShowClipboard ();
  399.             break;
  400.  
  401.         default:
  402.                 result = false;
  403.     } // switch
  404.  
  405.     return result;
  406. }
  407.